#!/bin/bash

# 获取第一个命令行参数作为设备名
device="$1"

# 定义挂载点和源文件路径
mount_point="/mnt"
source_file="lookup.uf2"

# 卸载指定设备
umount "$device" || {
    echo "Failed to unmount $device"
}

# 使用sync模式重新挂载设备
mount -o sync "$device" "$mount_point" || {
    echo "Failed to mount $device at $mount_point"
    exit 1
}

# 使用dd命令复制文件并显示进度
dd if="$source_file" of="$mount_point/$source_file" bs=256K status=progress || {
    echo "Failed to copy $source_file to $mount_point"
    exit 1
}
# 卸载
umount /mnt || {
    echo "Failed to unmount /mnt"
}

echo "Successfully copied $source_file to $mount_point"